<?php
session_start();
require_once __DIR__ . '/phpqrcode/qrlib.php'; // 引入 PHP QR Code 库

// 验证是否登录
if (!isset($_SESSION['username'])) {
    die("请先登录！");
}
require_once 'track_online.php';
// 获取并验证用户名
$targetUser = $_GET['user'] ?? null;

// 清理并验证用户名
$sanitizedUser = filter_var($targetUser, FILTER_SANITIZE_STRING);

// 如果用户名为空或非法，抛出错误
if (!$sanitizedUser) {
    die("用户参数无效！");
}

/*
// 生成二维码内容（目标用户主页链接）
$baseURL = "http://chat.jiil.top";
$qrcodeContent = $baseURL . "/userinfo.php?user=" . urlencode($sanitizedUser);

// 设置二维码生成路径
$qrDir = __DIR__ . '/qrcodes';
if (!is_dir($qrDir)) {
    mkdir($qrDir, 0777, true);
*/
}

$qrFile = $qrDir . '/' . md5($sanitizedUser) . '.png';
QRcode::png($qrcodeContent, $qrFile, QR_ECLEVEL_L, 6); // 生成二维码
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>好友二维码</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100vh;
            background-color: #f9f9f9;
        }
        h1 {
            font-size: 24px;
            color: #333;
        }
        .qr-code {
            margin: 20px 0;
        }
        p {
            font-size: 16px;
            color: #555;
            text-align: center;
            margin: 0 20px;
        }
        .loading {
            font-size: 16px;
            color: #888;
            text-align: center;
            margin-top: 10px;
        }
        .back-btn {
            margin-top: 20px;
            padding: 10px 20px;
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 5px;
            font-size: 16px;
            cursor: pointer;
            text-decoration: none;
        }
        .back-btn:hover {
            background-color: #45A049;
        }
    </style>
</head>
<body>
    <h1>好友主页二维码</h1>
    <div class="qr-code">
    <p>此功能已经被废弃,等待上线</p>
        <?php // <img src="<?= htmlspecialchars(str_replace(__DIR__, '', $qrFile)) ?>" alt="二维码"> ?>
    </div>
    <p>请截图，别人在菜单里通过扫描二维码可以快速到主页。</p>
    <a href="chat.php?id=<?= htmlspecialchars($sanitizedUser) ?>" class="back-btn">返回聊天</a>
</body>
</html>